# encoding:utf-8
from base import (dingding_push, read4csv, initialize_mt5, generate_data, get_rates4pos,
                  write_2csv, conversion_tradetime, convert_title, judge_trend, judge_macd, is_value_range,
                  dynamical_system, H4fH1,M15ftradetime,price_position_percentage,price_position_2percentage,
                  gen_ADX_probability,judge_Kline_color,check_position)
import pandas as pd
from pandas import Timedelta
import time
import MetaTrader5 as mt5
from datetime import datetime
import random

import yaml

with open('config.yaml', 'r', encoding='utf-8') as f:
    config = yaml.safe_load(f)
    run_mod = config['run_mod']
    begin = config['begin']
    symbol = config['symbols'][0]
    min_level= config['level']['min_level']
    mid_level= config['level']['mid_level']
    large_level= config['level']['lar_level']
    level_str = config['level']['title']
# print(run_mod)
# print(begin)
# print(symbol)
# print(min_level)
# print(mid_level)
# print(large_level)
# print(level_str)
# print()

# 240,1440,7200,15,60,240

begin_time = datetime.strptime(begin, "%Y.%m.%d %H:%M:%S")
i = 0
min_title = convert_title(min_level)
mid_title = convert_title(mid_level)
large_title = convert_title(large_level)

if run_mod == 'test':
    lar_df = read4csv(symbol, large_level)
    mid_df = read4csv(symbol, mid_level)
    min_df = read4csv(symbol, min_level)

# def mid_up_judge(prompt):
#     if mid_Mcolor[0] == 'red_blue':
#         prompt = prompt + '_中级别K线红后蓝，上升动力最强。'
#         min_golodens_push(prompt)
#     elif mid_Mcolor[0] == 'blue':
#         prompt = prompt + '_中级别K线蓝色，无禁止，或观望。'
#         min_golodens_push(prompt)
#     elif mid_Mcolor[0] == 'green':
#         prompt = prompt + '_中级别K线绿色，禁止做空。'
#         min_golodens_push(prompt)
#     elif mid_Mcolor[0] == 'red':
#         prompt = prompt + '_中级别K线红色，禁止做多。'

# def mid_down_judge(prompt):
#     if mid_Mcolor[0] == 'green_blue':
#         prompt = prompt + '_中级别K线绿后蓝，下降动力最强。'
#         min_golodens_push(prompt)
#     elif mid_Mcolor[0] == 'blue':
#         prompt = prompt + '_中级别K线蓝色，无禁止，或观望。'
#         min_golodens_push(prompt)
#     elif mid_Mcolor[0] == 'green':
#         prompt = prompt + '_中级别K线绿色，禁止做空。'
#         min_golodens_push(prompt)
#     elif mid_Mcolor[0] == 'red':
#         prompt = prompt + '_中级别K线红色，禁止做多。'

while True:
    if run_mod != 'test':
        if mt5.terminal_info() == None:
            initialize_mt5()
            print("执行MT5初始化！")

        # 生成数据
        base_number = 1000 # 十年521周
        # 生成大周期数据
        for level in (min_level,mid_level, large_level):  # 15,60,240,1440,7200
            if level == large_level : k_number = base_number
            elif level == mid_level : k_number = base_number * 5
            elif level == min_level : k_number = base_number * 5 * 5
            else: k_number = base_number
            rates_df = get_rates4pos(symbol, level, 0, k_number)
            tem_rates_df = rates_df[['time', 'open', 'high', 'low', 'close', 'tick_volume']]
            gen_df = generate_data(tem_rates_df)
            write_2csv(gen_df, symbol, level)

        lar_df = read4csv(symbol, large_level)
        mid_df = read4csv(symbol, mid_level)
        min_df = read4csv(symbol, min_level)

    if run_mod == 'test':
        # test_time = begin_time + Timedelta(minutes=mid_level * i)
        # test_time = begin_time + Timedelta(minutes=min_level * i)
        test_time = begin_time + Timedelta(minutes=mid_level * 60 * i)
        i += 1
        if test_time.weekday() >= 5:
            # 跳过周末
            continue
        min_test_time = conversion_tradetime(test_time,min_level)
        mid_test_time = conversion_tradetime(test_time,mid_level)
        lar_test_time = conversion_tradetime(test_time,large_level)

        min_df['TradeTime'] = pd.to_datetime(min_df['TradeTime'])
        mid_df['TradeTime'] = pd.to_datetime(mid_df['TradeTime'])
        lar_df['TradeTime'] = pd.to_datetime(lar_df['TradeTime'])

        min_target_df = min_df[min_df['TradeTime'] <= min_test_time]
        mid_target_df = mid_df[mid_df['TradeTime'] <= mid_test_time]
        lar_target_df = lar_df[lar_df['TradeTime'] <= lar_test_time]
        high = mid_target_df['high'].values[-1]
        low = mid_target_df['low'].values[-1]
        # high = min_target_df['high'].iloc[-1]
        # low = min_target_df['low'].iloc[-1]
        lasttick_ask = low + ((high - low) / 2)
        now = test_time

    elif run_mod != 'test':
        now = datetime.now()
        if now.weekday() >= 5:
            # 跳过周末
            continue
        min_target_df = min_df
        mid_target_df = mid_df
        lar_target_df = lar_df
        lasttick = mt5.symbol_info_tick(symbol)._asdict()  # 以列表的形式显示报价字段值
        lasttick_bid = lasttick['bid']
        lasttick_ask = lasttick['ask']

    min_BBup  = min_target_df['BBANDS_Up'].values[-1]
    min_BBlow = min_target_df['BBANDS_Low'].values[-1]
    min_EMA22 = min_target_df['EMA22'].values[-1]
    min_EMA13 = min_target_df['EMA13'].values[-1]
    min_EMA26 = min_target_df['EMA26'].values[-1]

    mid_BBup  = mid_target_df['BBANDS_Up'].values[-1]
    mid_BBlow = mid_target_df['BBANDS_Low'].values[-1]
    mid_EMA22 = mid_target_df['EMA22'].values[-1]
    mid_EMA13 = mid_target_df['EMA13'].values[-1]
    mid_EMA26 = mid_target_df['EMA26'].values[-1]

    lar_BBup  = lar_target_df['BBANDS_Up'].values[-1]
    lar_BBlow = lar_target_df['BBANDS_Low'].values[-1]
    lar_EMA22 = lar_target_df['EMA22'].values[-1]
    lar_EMA13 = lar_target_df['EMA13'].values[-1]
    lar_EMA26 = lar_target_df['EMA26'].values[-1]
    lar_FI = lar_target_df['FI'].iloc[-1]
    mid_FI = mid_target_df['FI'].iloc[-1]
    min_FI = min_target_df['FI'].iloc[-1]

    min_percentage = price_position_percentage(lasttick_ask, min_BBup, min_BBlow)
    mid_percentage = price_position_percentage(lasttick_ask, mid_BBup, mid_BBlow)
    lar_percentage = price_position_percentage(lasttick_ask,lar_BBup,lar_BBlow)
    min_percentage2 = price_position_2percentage(lasttick_ask, min_BBup, min_BBlow)
    mid_percentage2 = price_position_2percentage(lasttick_ask, mid_BBup, mid_BBlow)
    lar_percentage2 = price_position_2percentage(lasttick_ask,lar_BBup,lar_BBlow)
    min_trend_e22 = judge_trend(min_target_df, 'EMA22')
    mid_trend_e22 = judge_trend(mid_target_df, 'EMA22')
    lar_trend_e22 = judge_trend(lar_target_df, 'EMA22')
    min_trend_e11 = judge_trend(min_target_df, 'EMA11')
    mid_trend_e11 = judge_trend(mid_target_df, 'EMA11')
    min_macd = judge_macd(min_target_df)
    mid_macd = judge_macd(mid_target_df)
    lar_macd = judge_macd(lar_target_df)
    min_position = check_position(lasttick_ask,min_EMA13,min_EMA26)
    mid_position = check_position(lasttick_ask,mid_EMA13,mid_EMA26)

    print(lar_target_df.columns)
    print(now)

    print('大级别：')
    lar_ADX = lar_target_df['ADX'].tail(5).values
    lar_DI_plus = lar_target_df['DI+'].tail(5).values
    lar_DI_subtract = lar_target_df['DI-'].tail(5).values
    print(lar_ADX)
    print(lar_ADX[-1])
    print(lar_DI_plus)
    print(lar_DI_subtract)

    lar_ADX_down = lar_ADX[-4] > lar_ADX[-3] and lar_ADX[-3]<lar_ADX[-2] and lar_ADX[-2]<lar_ADX[-1]
    is_up = lar_DI_plus[-4]>lar_DI_subtract[-4] and lar_DI_plus[-3]>lar_DI_subtract[-3] and lar_DI_plus[-2]>lar_DI_subtract[-2] and lar_DI_plus[-1]>lar_DI_subtract[-1]
    is_down = lar_DI_plus[-4]<lar_DI_subtract[-4] and lar_DI_plus[-3]<lar_DI_subtract[-3] and lar_DI_plus[-2]<lar_DI_subtract[-2] and lar_DI_plus[-1]<lar_DI_subtract[-1]
    print(lar_ADX_down)
    print(is_up)
    print(is_down)
    input(11111111)
    # print(mid_target_df['ADX'])
    print('中级别：')

    # print(mid_ADX_down)
    # print(mid_begin_down)
    # print(mid_begin_up)
    print(is_down)
    print(is_up)

    ADX_probability = gen_ADX_probability(lar_ADX,lar_DI_plus,lar_DI_subtract)
    print(ADX_probability)
    mid_Mcolor = judge_Kline_color(mid_target_df,4675)
    lar_Mcolor = judge_Kline_color(lar_target_df, 'EMA11')
    print(mid_trend_e11)
    print(lar_trend_e22)
    print(lar_macd)
    print(lar_Mcolor[1])
    print(lar_Mcolor[0])
    print(mid_Mcolor[0])
    # red_blue blue green green_blue red
    # Underwater_Golden_Cross Above_Death_Cross
    min_Mcross_golodens = min_target_df['Underwater_Golden_Cross'].tail(7).values
    min_Mcross_deaths = min_target_df['Above_Death_Cross'].tail(7).values
    # print(min_Mcross_golodens)
    # print(min_Mcross_deaths)
    is_min_Mcross_golodens = any(min_Mcross_golodens)
    is_min_Mcross_deaths = any(min_Mcross_deaths)
    mid_Kcolor = mid_target_df['Kcolor'].tail(5).values
    lar_Kcolor = lar_target_df['Kcolor'].tail(5).values
    UB2_trend = mid_target_df['D2UB2_trend'].tail().values
    LB2_trend = mid_target_df['D2LB2_trend'].tail(5).values
    # print(lar_Kcolor[-1])
    # print(mid_Kcolor[-1])
    print('小级别是否水上死叉',is_min_Mcross_deaths)
    print('小级别是否水下金叉',is_min_Mcross_golodens)
    # print(UB2_trend)
    # print(LB2_trend)
    prompt = symbol+'['+level_str+']'+'提示：'+lar_Kcolor[-1]+'|中：'+mid_Kcolor[-1]
    if lar_Kcolor[-2] == 'red' and lar_Kcolor[-1]!='red':
        if mid_Kcolor[-1] !='red':
            prompt=prompt+';大中级别红色消失，可以买入！'
            if is_min_Mcross_golodens is True:
                prompt = prompt + ';小级别已经发生水下金叉'
                if 'test' != run_mod: dingding_push(prompt)
                # if mid_begin_up:
                #     prompt = prompt + ";中级别ADX上升"
                #     if 'test' != run_mod: dingding_push(prompt)
    if lar_Kcolor[-2] == 'green' and lar_Kcolor[-1] != 'green':
        if mid_Kcolor[-1] != 'green':
            prompt = prompt+ ';大中级别绿色消失，可以卖出！'
            if is_min_Mcross_deaths is True:
                prompt = prompt + ';小级别已经发生水上死叉'
                if 'test' != run_mod: dingding_push(prompt)
                # if mid_begin_down:
                #     prompt = prompt + ";中级别ADX下降"
                #     if 'test' != run_mod: dingding_push(prompt)

    print(prompt)
    if run_mod=='test':
        print('测试时间：',test_time)
        input('测试中，按任意键继续')
    else:
        time.sleep(min_level*60)

    '''
·如果你是日内动量交易者，只要两个时间周期都是绿色的你便可以买入，一旦其中之一变蓝或红，你便兑现收益；
·当尝试抓住市场拐点时，最好的交易信号不是绿色或者红色，而是红色或绿色开始消失时如果股价在下跌，但是你的分析显示已经接近市场底部，监控周
线图和日线图的动力系统。即使其中任意一个仍显示为红色，说明下降的趋势仍然很有力量，仍然禁止买入；当两个时间周期都不再显示为红色时，才允许买入。
如果你认为市场正在形成顶部，趋势即将反转。监控周线图和日线图的动力系统，如果任意一个仍然显示是绿色，说明上升趋势依然没有消失，禁止卖空。当两个时间周期的绿色都消失了时，你才可以卖空。
时间周期越短，它的信号就会越敏感：日线图上的动力系统开始改变颜色总会先于周线图。当做日内交易时，5分钟线图改变颜色要比25分钟线图早。如果我的分析表明市场正在筑底，即将开始反转，我
会等到日线图不再显示变红，开始变蓝，甚至变绿，然后我再去观察周线图，这时它仍然是红色的。一旦周线图从红色变蓝，系统会开始
允许买入。这种技术防止我当市场仍在下降的时候过早买入。我使用相同的方法进行卖空。当我认为市场的顶部正在形成，并
且日线图的动力不再显示绿色，开始变向蓝色甚至红色，然后我细心地观察周线图。一旦它不再显示为绿色，系统会开始允许卖空。等到
两个时间周期都不再显示与我的计划相对立的颜色，就能帮助我确保随着市场的方向进行交易，而不会逆势而行。一旦动力系统不再显示红
色，即使两个时间周期中只有其中一个改变了颜色，也马上清空你的空头头寸。最有效的下降部分已经结束，动力系统已经完成了它的使命。
    '''


    # input(111)
    # prompt = str(level)+''
    # if lar_Mcolor[0] == 'red_blue':  # 红后蓝，大级别有上升动力
    #     prompt=prompt+f"_{now}大级别K线红后蓝，有上升动力。"
    #     mid_up_judge(prompt)
    # elif lar_Mcolor[0] == 'blue':
    #     prompt = prompt + f"_{now}大级别K线为蓝色，无禁止，或观望。"
    #     mid_up_judge(prompt)
    # elif lar_Mcolor[0] == 'green_blue':
    #     prompt = prompt + f"_{now}大级别K线绿后蓝，有下降动力。"
    #     mid_down_judge(prompt)
    # else :
    #     prompt = prompt + f"_{now}_不是交易机会。\n"
    # dingding_push(prompt)

    # print(mid_trend_e22)
    # print(min_trend_e22)
    #
    # print(mid_macd)
    # print(min_macd)
    # todo: macd:up e11:up=g; macd:down e11:up=b; m:down e11:down=r; M:up e11:down = b
    # print(mid_BBup)
    # print(mid_BBlow)

    # print(lar_percentage)
    # print(mid_percentage)
    # print(min_percentage)

    # print(lar_percentage2)
    # print(mid_percentage2)
    # print(min_percentage2)

    # print(lar_FI)
    # print(mid_FI)
    # print(min_FI)
    # todo: ADX、EMA 判断大级别趋势；MACD（金叉死叉、柱型颜色EMA不同向观察）判断中级别的入场点，背离增加几率

    # input(1111111)


    # print('布林线位置百分比 ↓ （小中大）')
    # print('\n 根据22日均线判断方向 ↓')
    # print('\n MACD柱颜色 ↓ ')
    #
    # print('\n 与价值区的关系 ↓ (小中)')
    # print(min_position)
    # print(mid_position)
    # print('\n价格：',lasttick_ask)
    # if run_mod=='test':print('时间：',test_time)
    # print()
    # print(min_target_df.columns)
    # print(min_target_df['+DI'].tail(10))
    # input(33333)
    # score=0
    # message = []

'''
    # 策略1：价格背离+假突破
    # 关键位，M柱、线、FI与E22背离

    # 策略2：回调到价值区
    # E22上升，离开布林上轨，M柱gb，止盈价值区、M柱rb
    # E22下降，远离布林下轨，M柱rb，止盈价值区，M柱rb

    # 价值区反转，加仓位
    # E22上升，价值区、布林中轨附近，M柱rb/g，中级别在布林下轨、M柱rb，更小级别M|E金叉
    # E22下降，价值区、布林中轨附近，M柱gb/r，中级别在布林上轨、M柱gb，更小级别M|E死叉
    #  注意市场大部分时间在波动，不要期望每天都有机会！！

    if 'down' in lar_trend_e22[0]:
        message.append('大E22' + lar_trend_e22[1])
        if 'down' in lar_macd[0]:
            message.append('大' + lar_macd[1])
            if 'ngb'  == lar_macd[3]: score = score + 3; message.append('大新蓝柱+3')
            elif 'gb' == lar_macd[3]: score = score + 2; message.append('大蓝柱+2')
            elif 'r'  == lar_macd[3]: score = score + 1; message.append('大红柱+1')

            # if 100 >= mid_percentage >= 75:score = score + 3; message.append('中布林上轨附近！+3')
            # elif 75 >= mid_percentage > 50:score = score + 2; message.append('中布林中轨附近偏上！+2')
            # elif 50 >= mid_percentage > 25:score = score + 1; message.append('中布林中轨附近偏下！+1')
            # elif 25 >= mid_percentage >= 0:score = score + 0; message.append('中布林下轨附近！')

            if mid_macd[3] == 'ngb':
                score = score + 3; message.append('中MACD柱为新近绿后蓝！+3')
                if 'above'     in mid_position:score = score + 2; message.append('中价值区上+2')
                elif 'between' in mid_position:score = score + 1; message.append('中价值区中+1')
            elif mid_macd[3] == 'gb':
                score = score + 2; message.append('中MACD柱为绿后蓝！+2')
                if 'above'     in mid_position:score = score + 2; message.append('中价值区上+2')
                elif 'between' in mid_position:score = score + 1; message.append('中价值区中+1')
            elif mid_macd[3] == 'r':
                score = score + 1; message.append('中MACD柱为红色！+1')
                if 'above'     in mid_position:score = score + 2; message.append('中价值区上+2')
                elif 'between' in mid_position:score = score + 1; message.append('中价值区中+1')

            if min_macd[3] == 'ngb':
                score = score + 3; message.append('小MACD柱为新近绿后蓝！+3')
                if 'above' in min_position:score = score + 2; message.append('小价值区上+2')
                elif 'between' in min_position:score = score + 1; message.append('小价值区中+1')

            elif min_macd[3] == 'gb':
                score = score + 2; message.append('小MACD柱为绿后蓝！+2')
                if 'above'     in min_position:score = score + 2; message.append('小价值区上+2')
                elif 'between' in min_position:score = score + 1; message.append('小价值区中+1')

            elif min_macd[3] == 'r':
                score = score + 1; message.append('小MACD柱为红色！+1')
                if 'above'     in min_position:score = score + 2; message.append('小价值区上+2')
                elif 'between' in min_position:score = score + 1; message.append('小价值区中+1')

    elif 'up' in lar_trend_e22[0] :
        message.append('大E13'+lar_trend_e22[1])
        if 'up' in lar_macd[0]:
            message.append('大' + lar_macd[1])
            if 'nrb'  == lar_macd[3]: score = score + 3; message.append('大新紫柱+3')
            elif 'rb' == lar_macd[3]: score = score + 2; message.append('大旧紫柱+2')
            elif 'g'  == lar_macd[3]: score = score + 1; message.append('大绿柱+1')

            # if 100 >= mid_percentage >= 75:score = score + 0; message.append('中布林上轨附近超75%！+0')
            # elif 75 >= mid_percentage > 50:score = score + 1; message.append('中布林中轨近偏上50%至75%！+1')
            # elif 50 >= mid_percentage > 25:score = score + 2; message.append('中布林中轨近偏下25%至50%！+2')
            # elif 25 >= mid_percentage >= 0:score = score + 3; message.append('中布林下轨附近！+3')

            if mid_macd[3] == 'nrb' :
                score = score + 3; message.append('中MACD柱为新近红后紫！+3')
                if 'below' in mid_position: score = score + 2; message.append('中价值区下+2')
                elif 'between' in mid_position:score = score + 1; message.append('中价值区中+1')
            elif mid_macd[3] == 'rb':
                score = score + 2; message.append('中MACD柱为多次红后紫！+2')
                if 'below' in mid_position:score = score + 2; message.append('中价值区下+2')
                elif 'between' in mid_position:score = score + 1; message.append('中价值区中+1')
            elif mid_macd[3] == 'g' :
                score = score + 1; message.append('中MACD柱为绿色，+1！')
                if 'below'     in mid_position:score = score + 2; message.append('中价值区下+2')
                elif 'between' in mid_position:score = score + 1; message.append('中价值区中+1')

            if min_macd[3] == 'nrb' :
                score = score + 3; message.append('小MACD柱为新近红后紫！+3')
                if 'below'     in min_position:score = score + 2; message.append('小价值区下+2')
                elif 'between' in min_position:score = score + 1; message.append('小价值区中+1')
            elif min_macd[3] == 'rb':
                score = score + 2; message.append('小MACD柱为多次红后紫！+2')
                if 'below'     in min_position:score = score + 2; message.append('小价值区下+2')
                elif 'between' in min_position:score = score + 1; message.append('小价值区中+1')
            elif min_macd[3] == 'g' :
                score = score + 1; message.append('小MACD柱为绿色，+1！')
                if 'below'     in min_position:score = score + 2; message.append('小价值区下+2')
                elif 'between' in min_position:score = score + 1; message.append('小价值区中+1')


    else:
        message.append('混沌时期！')
    print(message)
    print(test_time)
    # input(133)


    # 策略3：针对极值


    trade_direction = 'buy'
    # 接近/超越上轨，M柱gb，


    # trade_direction = 'down'
    # 接近/超越下轨，M柱rb
    # if 100 >= mid_percentage >= 75: score = score + 3
    # # price = 2760
    # key_level = [2700,2800]



    print('实时买价:',lasttick_ask)
    print(symbol,prompt+',得分：【'+str(score)+'】 '+str(message))
    print(str(min_target_df.tail(1)['TradeTime'].item()))

    if run_mod == 'test':
        if score >= 6:
            input('=== pause ===')
            print()
        time.sleep(0.3)
    if run_mod != 'test':
        if score >= 5:
            dingding_push(f'{symbol},'+prompt+',提示，得分：【'+str(score)+'】 '+str(message))
        time.sleep(mid_level*50)






#
# lar_trend = lar_df['trend'].tail(1).item()
# mid_trend = mid_df['trend'].tail(1).item()
#
# print(lar_trend, mid_trend)
# input('=== pause ===')
#
# # last_EMA13 = mid_df.tail(1)['EMA13'].values[0]
# last_EMA13 = mid_df.tail(1)['EMA13'].item()
# last_EMA26 = mid_df.tail(1)['EMA26'].item()
# # print(last_EMA13)
# # print(last_EMA26)
# mid_position = check_position(lasttick_bid, last_EMA13, last_EMA26)
# print(mid_position)
# # 大级别下降趋势，中级别k线回调到价值区中或价值区上，M柱由绿变为蓝反转向下，为好的入场点，M柱变红稍差
# lar_BBup = lar_df.tail(1)['BBANDS_Up'].item()
# lar_BBmid = lar_df.tail(1)['BBANDS_Mid'].item()
# lar_BBlow = lar_df.tail(1)['BBANDS_Low'].item()
# score = 0
# if lar_trend == 'Down':
#     # BBANDS_Up	BBANDS_Mid BBANDS_Low
#     print(large_title, "下降趋势")
#     p = price_position_percentage(lasttick_ask, lar_BBup, lar_BBlow)
#     print("百分百：", p)
#
#     # if distance_BBlow > 0:
#     #     print('价格在BB下轨之下,需要随时注意向上回调。')
#
#     input(22)
#     if mid_position == 'between':
#         print(mid_title, "价值区中")
#         macd_status = judge_macd(mid_df)
#         print(macd_status)
#     elif mid_position == 'above':
#         print(mid_title, "价值区上")
#         macd_status = judge_macd(mid_df)
#         print(macd_status)
#     elif mid_position == 'below':
#         print(mid_title, "价值区下")
#         macd_status = judge_macd(mid_df)
#         print(macd_status)
#
# input(2222)
#
# mid_EMA_max = mid_df.tail(10)['EMA22'].max()
# lar_EMA_max = lar_df.tail(10)['EMA22'].max()
# print(mid_EMA_max)
# print(lar_EMA_max)
# mid_EMA_min = mid_df.tail(10)['EMA22'].min()
# lar_EMA_min = lar_df.tail(10)['EMA22'].min()
# print(mid_EMA_min)
# print(lar_EMA_min)
#
# mid_EMA_idxmax = mid_df.tail(10)['EMA22'].idxmax()
# lar_EMA_idxmax = lar_df.tail(10)['EMA22'].idxmax()
# print(mid_EMA_idxmax)
# print(lar_EMA_idxmax)
# mid_EMA_idxmin = mid_df.tail(10)['EMA22'].idxmin()
# lar_EMA_idxmin = lar_df.tail(10)['EMA22'].idxmin()
# print(mid_EMA_idxmin)
# print(lar_EMA_idxmin)
# indices = mid_df.tail(10)['EMA22'].index
# mid_EMA_idxall = indices.tolist()
# print()
# print(mid_EMA_idxmax)
# print(mid_EMA_idxmin)
# print(mid_EMA_idxall)
'''